﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;

namespace EasyTest {

    /// <summary>
    /// Autocomplete textbox object.
    /// </summary>
    public class AutoComplete : TextBox {
        //private string FindBy { get; set; }
        //private Focus Focus { get; set; }

        /// <summary>
        /// Gets and Sets the text to perform the FindBy operation for the AutoComplete object.
        /// </summary>
        private string AutoCompleteFindBy { get; set; } 

        /// <summary>
        /// Create new AutoComplete object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="autoCompleteFindBy">HTML text to identify and find the AutoComplete object within a document.</param>
        public AutoComplete(string findBy, string autoCompleteFindBy)
            : base(findBy) {
            AutoCompleteFindBy = autoCompleteFindBy;
        }

        /// <summary>
        /// Create new AutoComplete object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="autoCompleteFindBy">HTML text to identify and find the AutoComplete object within a document.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        public AutoComplete(string findBy, string autoCompleteFindBy, Focus focus)
            : this(findBy, autoCompleteFindBy) {
            Focus = focus;
        }

        /// <summary>
        /// Set the Action to find the AutoComplete object.
        /// </summary>
        /// <param name="text">String representing the object to find.</param>
        public void Set(string text) {
            Focus.Go();
            Action.Set(FindBy, text);
            Action.WaitFor(AutoCompleteFindBy, 5);
            Action.Set(FindBy, Keys.Down);
            Action.Set(FindBy, Keys.Enter);
            Action.Set(FindBy, Keys.Tab);
        }
    }
}
